<template>
  <div class="table-page-search-wrapper" style="margin-top: 20px;">
    <a-form layout="inline" @keyup.enter.native="search">
      <a-row :gutter="48">
        <a-col :xxl="8" :xl="8" :lg="8" :sm="24">
          <a-form-item label="关键字">
            <a-input
              v-model="queryParam.keyWord"
              placeholder=" 请输入关键字"
              allowClear
            />
          </a-form-item>
        </a-col>
        <a-col v-if="type !=5" :xxl="8" :xl="8" :lg="8" :sm="24">
          <a-form-item label="时间" has-feedback>
            <a-range-picker
              style="width:100%;"
              show-time
              valueFormat="YYYY-MM-DD HH:mm:ss"
              format="YYYY-MM-DD HH:mm:ss"
              v-model="queryParam.time"
            />
          </a-form-item>
        </a-col>
         <a-col v-if="type == 4" :xxl="4" :xl="4" :lg="4" :sm="24">
          <a-form-item has-feedback>
            <a-select v-model="queryParam.taskObject" placeholder="请选择">
                <a-select-option value="3">导购</a-select-option>
                <a-select-option value="2">用户</a-select-option> 
              </a-select>
          </a-form-item>
        </a-col>
        <a-col :xxl="24" :xl="24" :lg="24"
              :sm="24">
          <span class="table-page-search-submitButtons">
            <a-button type="primary" @click="search">查询</a-button>
            <a-button style="margin-left: 8px" @click="reset">重置</a-button>
            <a-button v-if="type==1" type="primary" icon="plus" style="margin-left: 8px" @click="handleAddAd">新增广告</a-button>
            <template v-if="type==2">
              <a-button type="primary" style="margin-left: 8px" @click="handleMessageTypeList">消息类型管理</a-button>
              <a-button type="primary" icon="plus" style="margin-left: 8px" @click="handleAddMessage">新增消息</a-button>
            </template>
            <a-button v-if="type==3" type="primary" icon="plus" style="margin-left: 8px" @click="handleAddMessageType">新增消息类型</a-button>
            <template v-if="type==4">
              <a-button type="primary" icon="plus" style="margin-left: 8px" @click="handleAddTask">新增任务</a-button> 
            </template>
            <a-button v-if="type==5" type="primary" style="margin-left: 8px" @click="handleExport">导出</a-button>
          </span>
        </a-col>
      </a-row>
    </a-form>
  </div>
</template>
<script>

  export default {
    props: {
      type: { // 1:广告位管理 // 2:消息推送 3: 消息类型管理 4: 任务管理 5:任务明细管理
        type: [String, Number],
        default: 1
      },
      activeKey: { 
        type: [String, Number],
        default: 1
      }
    },
    data() {
      return {
        memberType: 1,
        queryParam: {
          taskObject: '3'
        }
      }
    },
    computed: {
    },
    created() {
    },
    mounted() {
    },
    methods: {
      // 导出
      handleExport() {
        this.$emit('onExport')
      },

       // 消息类型管理
      handleMessageTypeList() {
        this.$router.push(`/micromall/community/marketingManagement/messageTypeList`)
      },

      // 新增任务
      handleAddTask() {
        this.$emit('onAddTask', null)
      },

      // 新增消息类型
      handleAddMessageType() {
        this.$emit('onAddMessageType', null)
      },

      // memberTypeChange(e) {
      //   this.taskObject = e.target.value
      //   this.$emit('onMemberTypeChange', e.target.value)
      // },

      // 新增广告
      handleAddAd() {
        this.$emit('onAddAd', null)
      },

      // 新增广告
      handleAddMessage() {
        this.$emit('onAddMessage', null)
      },

      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        )
      },

      search() {
        let queryParam = this.filterFields(this.queryParam)
        this.$emit('onSearch', queryParam)
      },

      reset() {
        this.queryParam = {
          taskObject: '3'
        }
        let queryParam = this.filterFields(this.queryParam)
        this.$emit('onSearch', queryParam)
      },

      filterFields(values) {
        const formValue = {}
        Object.keys(values).forEach(i => {
          if (values[i] && values[i].length) {
            if (i === 'time') {
              console.log('time')
              formValue.startTime = values[i][0]
              formValue.endTime = values[i][1]
            } else {
              formValue[i] = values[i]
            }

          }
        })
        return formValue
      }
    }
  }
</script>
<style lang="less" scoped>
  .table-page-search-submitButtons {
    display: flex;
    justify-content: flex-end;
  }
</style>
